package com.example.arithmeticleetcode.leetcode.october;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-15 09:16
 **/
public class Demo06 {

    public static void main(String[] args) {
        System.out.println(tribonacci(25));
    }

    public static int tribonacci(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1 || n == 2) {
            return 1;
        }
        int sum = 0;
        int T0 = 0;
        int T1 = 1;
        int T2 = 1;
        while (n >= 3) {
            sum = T0 + T1 + T2;
            T0 = T1;
            T1 = T2;
            T2 = sum;
            n--;

        }
        return sum;
    }
}
